/***************************************************************************
 *   Copyright (C) 2008 by JBox systems
 *   gabi@shaargiora.co.il
 *
 *   This program is free software; you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation; either version 3 of the License, or
 *   (at your option) any later version.
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with this program; if not, write to the
 *   Free Software Foundation, Inc.,
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 ***************************************************************************/

// NOTE boost/logging log.h must be included before qt headers.
// #include "log.h"

#include <QApplication>
#include <string>
#include <boost/filesystem.hpp>

#include "log.h"
#include "gui.h"
#include "controller.h"
#include "const.h"

/**
	Path to the executable.
*/
std::string path_to_database;

int main(int argc, char** argv) {

	Q_INIT_RESOURCE(resources);

	Logger::init(LOGFILE);
	LOG ( "Log started")

	QApplication app(argc, argv);

	path_to_database = (boost::filesystem::path(argv[0]).parent_path() / "database").string();

	Controller *controller = new Controller();

	AutoMateUi* ui = new AutoMateUi;

	app.connect(ui, SIGNAL(downloadVersions(std::vector<Version>)), controller, SLOT(downloadVersions(std::vector<Version>)));
	ui->show();
	app.connect(controller, SIGNAL(dataReadProgress(int, int)), ui, SLOT(updateDataReadProgress(int, int)));
	app.connect(ui, SIGNAL(abortDownloads()), controller, SIGNAL(abortDownloads()));
	app.connect(controller, SIGNAL(downloadsFinished()), ui, SLOT(resetDownloadAction()));
	app.connect(controller, SIGNAL(downloadsAborted()), ui, SLOT(resetDownloadAction()));
	app.connect(controller, SIGNAL(status(QString)), ui, SLOT(updateStatusMessage(QString)));

	return app.exec();
}
